using System.Collections.Generic;
using UnityEngine;

namespace DA.AnimGraph {
    
    /// <summary>
    /// debug用，构造AGController内部AG的连接情况
    /// </summary>
    public class AGTree {
        public List<AGTreeEntry> data => tree;
        private List<AGTreeEntry> tree;
        public AGTree() {
            tree = new();
            tree.Add(new AGTreeEntry() {
                slotName = "root",
            });
        }
        public AGTreeEntry this[int index] {
            get {
                return tree[index];
            }
        }

        public void AddToSlot(string slotName, int indexInArray, string name, int slotPort) {
            int index = -1;
            for (int i = 0; i < tree.Count; i++) {
                if (tree[i].slotName == slotName) {
                    index = i;
                    break;
                }
            }
            if (index == -1) {
                Debug.LogError($"未找到该slot {slotName}");
                return;
            }
            var e = tree[index];
            if (slotPort == 0) {
                e.indexInArray0 = indexInArray;
                e.name0 = name;
            } else {
                e.indexInArray1 = indexInArray;
                e.name1 = name;
            }
            e.isFill = true;
            tree[index] = e;
        }
        public void NewSlot(string slotName, int level, int curPort) {
            tree.Add(new AGTreeEntry() {
                slotName = slotName,
                level = level,
                curPort = curPort,
            });
        }
    }

    public struct AGTreeEntry {
        public int level;
        public string slotName;
        public string name0;
        public string name1;
        public int indexInArray0;
        public int indexInArray1;
        public int curPort;
        public bool isFill; // slot是否被连接
    }
}
